package com.easylinkin.linkappapi.investigation.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.investigation.entity.InvestigationType;
import com.easylinkin.linkappapi.investigation.service.InvestigationTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import java.util.List;

/**
 * @author ckx
 * @desc 排查类型
 * @date 2020-04-13
 */
@RestController
@RequestMapping("/investigation/investigationType")
public class InvestigationTypeController {

    @Autowired
    InvestigationTypeService service;

    @PostMapping("getPage")
    public RestMessage getPage(@RequestBody RequestModel<InvestigationType> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<InvestigationType> record = service.getInvestigationTypePage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(record).build();
    }

    @GetMapping("getAll")
    public RestMessage getAll() {
        List<InvestigationType> record = service.getInvestigationTypeAll();
        return RestBuilders.successBuilder().data(record).build();
    }


    @PostMapping("update")
    public RestMessage update(@RequestBody InvestigationType investigationType) {
        return RestBuilders.successBuilder(service.updateInvestigationType(investigationType)).build();
    }

    @PostMapping("add")
    public RestMessage add(@RequestBody InvestigationType investigationType) {
        return RestBuilders.successBuilder(service.addInvestigationType(investigationType)).build();
    }

    @PostMapping("deleteBatch")
    public RestMessage deleteBatch(@RequestBody List<InvestigationType> investigationTypeList) {
        Assert.notEmpty(investigationTypeList, "参数为空");
        return RestBuilders.successBuilder(service.delInvestigationTypeList(investigationTypeList)).build();
    }
}
